package com.ytjj.qmyx.admin.controller.imController;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.dto.ImConfigValueInfoDto;
import com.ytjj.qmyx.admin.model.vo.ImConfigValueInfoVO;
import com.ytjj.qmyx.admin.service.imService.ImConfigValueInfoService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 客服设置详情管理controller
 */
@RestController
@RequestMapping("/imConfigValue")
@Slf4j
public class ImConfigValueInfoController {

    @Autowired
    private ImConfigValueInfoService imConfigValueInfoService;

    /**
     * 修改设置
     * 参数: "id","threshold","content"
     * @return 修改个数
     *
     */
    @PostMapping("/saveConfigValue")
    public CommonResult saveConfigValue(@RequestBody ImConfigValueInfoVO request){
        Integer adminId = UserUtil.getAdminId();
        request.setUpdateUser(adminId);
        int count = imConfigValueInfoService.saveConfigValue(request);
        if (count > 0){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }


    /**
     * 修改设置
     * 参数: "id","threshold","content"
     * @return 修改个数
     *
     */
    @PostMapping("/updateConfigValue")
    public CommonResult updateConfigValue(@RequestBody ImConfigValueInfoVO request){
        Integer adminId = UserUtil.getAdminId();
        request.setUpdateUser(adminId);
        int count = imConfigValueInfoService.updateConfigValue(request);
        if (count > 1){
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }

    /**
     * 获取设置详情
     * @return
     */
    @GetMapping("/getConfigValue")
    public CommonResult getConfigValue(){
        return CommonResult.success(imConfigValueInfoService.getConfigValue());
    }
}
